
--[[

    slimui - Copyright (c) 2011 atom0s, All rights reserved.

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

]]--

----------------------------------------------------------------------------------
-- slimUI Global Definition
----------------------------------------------------------------------------------
slimui = { 
    ------------------------------------------------------------------------------
    -- The current version of this package.
    ------------------------------------------------------------------------------
    SLIMUI_VERSION  = "1.0.2",
    
    ------------------------------------------------------------------------------
    -- This beta flag is used when a version is not yet marked to be release
    -- quality. Beta versions will include experiemental code or fixes that
    -- are still being worked on or tested publicly.
    ------------------------------------------------------------------------------
    SLIMUI_BETA     = true,
    
    ------------------------------------------------------------------------------
    -- Debug mode allows users to better understand where something may be
    -- going wrong. Only enable debug mode if you wish to see various messages
    -- printed out while using slimui. Normal users will want to keep this off!
    ------------------------------------------------------------------------------
    SLIMUI_DEBUG    = true,
};

----------------------------------------------------------------------------------
-- func: slimui:version
-- desc: Returns the current slimUI version that is loaded.
----------------------------------------------------------------------------------
function slimui:version( )
    return self.SLIMUI_VERSION;
end

----------------------------------------------------------------------------------
-- func: slimui:isbeta
-- desc: Returns if beta mode is enabled for slimUI.
----------------------------------------------------------------------------------
function slimui:isbeta( )
    return self.SLIMUI_BETA;
end

----------------------------------------------------------------------------------
-- func: slimui:isdebug
-- desc: Returns if debug mode is enabled for slimUI.
----------------------------------------------------------------------------------
function slimui:isdebug( )
    return self.SLIMUI_DEBUG;
end

----------------------------------------------------------------------------------
-- func: slimui:msg
-- desc: Prints a message specific to slimUI.
----------------------------------------------------------------------------------
function slimui:msg( text )
    print( '[slimUI] ' .. text );
end

----------------------------------------------------------------------------------
-- func: slimui:err
-- desc: Prints a message specific to slimUI as an error.
----------------------------------------------------------------------------------
function slimui:err( text )
    error( '[slimUI:ERROR] ' .. text );
end

----------------------------------------------------------------------------------
-- func: slimui:loadDirectory
-- desc: Loops a directory and loads each Lua file.
----------------------------------------------------------------------------------
function slimui:loadDirectory( dir, ignore )
    local fullPath = getCheatEngineDir() .. dir;
    local f = io.popen( string.format( 'dir "%s" /B', fullPath ) );
    
    if f == nil then
        slimui:err( 'loadDirectory failed to obtain directory list.' );
    end
    
    for n in f:lines() do
        if ignore == nil or type( ignore ) ~= 'table' then
            require( dir .. '/' .. string.sub( n, 0, string.len( n ) - 4 ) );
        else
            if table.hasValue( ignore, n ) == false then
                require( dir .. '/' .. string.sub( n, 0, string.len( n ) - 4 ) );
            end
        end
    end
    
    f:close();
end

--[[ -----------------------------------------------------------------------------

    File Inclusion

    The inclusion order of files matters. Classes depend on each other and must be
    loaded in the proper order! Assert errors will occur if you load any class out
    of order. If your class needs to be loaded prior to another, use the ignore
    list and manually load your class first.

]]-- -----------------------------------------------------------------------------

if ( slimui:isdebug() == true ) then
    local oldRequire = require
    function require( path )
        slimui:msg( 'including: ' .. path );
        oldRequire( path );
    end
end

require( 'slimui/extensions/class' );
require( 'slimui/extensions/table' );

require( 'slimui/bases/object' );
require( 'slimui/bases/component' );
require( 'slimui/bases/control' );
require( 'slimui/bases/wincontrol' );
slimui:loadDirectory( 'slimui/bases', { 'object.lua', 'component.lua', 'control.lua', 'wincontrol.lua' } );

slimui:loadDirectory( 'slimui/controls', nil );


--[[ Debug information. ]]--------------------------------------------------------
if ( slimui:isdebug() == true ) then
    slimui:msg( 'slimUI.lua successfully loaded. [Version:' .. slimui:version() .. '][Beta:' .. tostring( slimui:isbeta() ) .. ']' );
end